//
//  Action_collectionViewCellGoods.m
//  EggSteward
//
//  Created by 王道林 on 16/9/3.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "Action_collectionViewCellGoods.h"
#import "BaseLabel.h"
#import "BaseView.h"
#import "DLMacro.h"
#import "Masonry.h"
#import "ShopGoodModel.h"
#import "UIImageView+WebCache.h"
@interface Action_collectionViewCellGoods ()

@property (nonatomic, strong) UIImageView *imageview;
@property (nonatomic, strong) UIImageView *imageViewAgg;
@property (nonatomic, strong) BaseLabel *lableName;
@property (nonatomic, strong) BaseLabel *lableAgg;
@property (nonatomic, strong) BaseView *view;
@end

@implementation Action_collectionViewCellGoods

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubview];
    }
    return self;
}

- (void)createSubview
{
    _view = [[BaseView alloc] init];
    [self.contentView addSubview:_view];
    _view.layer.masksToBounds = YES;
    _view.layer.borderWidth = 2;
    _view.layer.borderColor =[[UIColor grayColor] CGColor];
    
    _imageview = [[UIImageView alloc] init];
    [_view addSubview:_imageview];
    
    _imageViewAgg = [[UIImageView alloc] init];
    _imageViewAgg.image = [UIImage imageNamed:@"jidan"];
    [_view addSubview:_imageViewAgg];
    
    _lableName = [[BaseLabel alloc] init];
    [_view addSubview:_lableName];
    
    _lableAgg = [[BaseLabel alloc] init];
    [_view addSubview:_lableAgg];;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [_view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_top);
        make.left.mas_equalTo(self.contentView.mas_left);
        make.bottom.mas_equalTo(self.contentView.mas_bottom);
        make.right.mas_equalTo(self.contentView.mas_right);
    }];
    
    [_imageview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_view.mas_top);
        make.left.mas_equalTo(_view.mas_left);
        make.height.mas_equalTo(_view.mas_height).multipliedBy(0.7);
        make.right.mas_equalTo(_view.mas_right);
    }];
    
    [_lableName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_imageview.mas_bottom).mas_offset(5);
        make.left.mas_equalTo(_view.mas_left).mas_offset(5);
        make.width.mas_equalTo(_view.mas_width).multipliedBy(0.5);
        make.bottom.mas_equalTo(_view.mas_bottom).mas_offset(-5);
    }];

    [_imageViewAgg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_imageview.mas_bottom).mas_offset(20);
        make.left.mas_equalTo(_lableName.mas_right).mas_offset(5);
        make.height.mas_equalTo(_lableName.mas_height).multipliedBy(0.4);
        make.width.mas_equalTo(_lableName.mas_height).multipliedBy(0.4);
    }];
    
    [_lableAgg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_imageview.mas_bottom).mas_offset(5);
        make.left.mas_equalTo(_imageViewAgg.mas_right);
        make.height.mas_equalTo(_lableName.mas_height);
        make.right.mas_equalTo(_view.mas_right);
    }];


    
}

- (void)setShopGoddModel:(ShopGoodModel *)shopGoddModel
{
    _shopGoddModel = shopGoddModel;
    [_imageview sd_setImageWithURL:[NSURL URLWithString:_shopGoddModel.pic] placeholderImage:[UIImage imageNamed:@"1203"]];
    _lableName.text = _shopGoddModel.goods_name;
    _lableAgg.text = _shopGoddModel.money_need;
}




@end
